﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleCasino
{
    public class Menu
    {
        public int Selected{ get; private set; } // Currently selected MenuItem
        public string Name { get; protected set; }
        public MenuItem[] MenuItems { get; protected set; }
        
        public Menu(string name, MenuItem[] menuItems)
        {
            this.Name = name;
            this.MenuItems = menuItems;
            this.Selected = 0;
        }
        // Gets input from the player, moves the selected if it is Left or Right button and calls MenuItem.Perform() if Enter
        public void CheckInput(PlayerInput input)
        {
            if (input != PlayerInput.Idle)
            {
                if (input == PlayerInput.MoveLeft && this.Selected != 0)
                {
                    this.Selected--;
                }
                else if (input == PlayerInput.MoveRight && this.Selected != (MenuItems.Length - 1))
                {
                    this.Selected++;
                }
                else if (input == PlayerInput.Choose)
                {
                    MenuItems[Selected].Perform();
                }
            }
        }
    }
}
